Xbasic

EVALUATE_STRING Function

Syntax

Transformed_String as C = evaluate_string(string as c[,variableFrame as p])

Arguments

Transformed_String

A character string with values substituted for placeholders.

string

A character string with placeholders.

variableFrame

Optional. Default = LOCAL_VARIABLES(). The variable frame to examine for variables.

Description

Replaces all variables/expressions in a string with their actual values. Variables/expressions are enclosed in { }. Use \{ or \} to escape the soft brace character.

Discussion

The EVALUATE_STRING() function replaces placeholders in a string with variable values and returns a transformed string. Each placeholder is a variable name or expression surrounded by curly braces "{}". Note: If you are using evaluate_string() in a loop, it is more efficient to compile the template.

Example

dim firstname as c = "Tom"
dim lastname as c = "Smith"
dim dob as d = {12/12/1980}
string = "My name is {firstname} {ut(lastname)} and I was born on {dob}"
? evaluate_string(string)
= "My name is Tom SMITH and I was born on 12/12/1980"
dim v as P
v.firstname = "Sheila"
v.lastname = "Smith"
v.dob = {1/1/1972}
? evaluate_string(string, v)
= "My name is Sheila SMITH and I was born on 01/01/1972"

See Also